//
//  LZTimeLimitCountDownJudgeDataManager.m
//  laziz_Consumer
//
//  Created by xbn_iMac on 2016/11/18.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZTimeLimitCountDownJudgeDataManager.h"

@implementation LZTimeLimitCountDownJudgeDataManager

/**
 *  @author taohebin, 16-07-11 14:07:26
 *
 *  设置倒计时label样式
 *
 *  @param xLimitLabel 倒计时的label
 *  @param xRemain     倒计时时间 -1默认不做处理
  *  @param hourUnit   小时的单位
  *  @param minUnit    分钟的单位
  *  @param secUnit    秒的单位
  *  @param isChangeUnitColor     是否要换单位的颜色
  *  @param hourUnitColor     小时的单位颜色
  *  @param minUnitColor      分钟的单位颜色
  *  @param secUnitColor      秒的单位颜色
 */
+(void)configLimitedLabel:(UILabel *)xLimitLabel withReamin:(NSTimeInterval)xRemain andHourUnit:(NSString*)hourUnit andMinuteUnit:(NSString*)minUnit andSecUnit:(NSString*)secUnit andIsChangeUintColor:(BOOL)isChangeUnitColor andHourUnitColor:(UIColor*)hourUnitColor andMinUnitColor:(UIColor*)minUnitColor andSecUnitColor:(UIColor*)secUnitColor {
    if (xRemain == -1) {
        return;
    }
    
    int second = (int)xRemain  % 60;
    int minute = ((int)xRemain / 60) % 60;
    int hours = xRemain / 3600;
    
    NSMutableString *secondStr = [NSMutableString stringWithFormat:@"%02d",second];
    NSMutableString *minuteStr = [NSMutableString stringWithFormat:@"%02d",minute];
    NSMutableString *hoursStr = [NSMutableString stringWithFormat:@"%02d",hours];
    
    
    NSString *result = [NSString stringWithFormat:@"%@%@%@%@%@%@" ,hoursStr,hourUnit,minuteStr,minUnit,secondStr,secUnit];
    
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",result]];
    if (isChangeUnitColor) {
        NSRange range_h = [result rangeOfString:hourUnit];
        NSRange range_m = [result rangeOfString:minUnit];
        NSRange range_s = [result rangeOfString:secUnit];
        
        [attributeString setAttributes:@{NSForegroundColorAttributeName:hourUnitColor} range:range_h];
        [attributeString setAttributes:@{NSForegroundColorAttributeName:minUnitColor} range:range_m];
        [attributeString setAttributes:@{NSForegroundColorAttributeName:secUnitColor} range:range_s];
    }
    
    xLimitLabel.attributedText = attributeString;
}

+(void)configLimitedLabel:(UILabel *)xLimitLabel withReamin:(NSTimeInterval)xRemain andDayUnit:(NSString *)dayUnit HourUnit:(NSString*)hourUnit andMinuteUnit:(NSString*)minUnit andSecUnit:(NSString*)secUnit andIsChangeUintColor:(BOOL)isChangeUnitColor andDayUnitColor:(UIColor *)dayUnitColor HourUnitColor:(UIColor*)hourUnitColor andMinUnitColor:(UIColor*)minUnitColor andSecUnitColor:(UIColor*)secUnitColor
{
    if (xRemain == -1) {
        return;
    }
    
    int second = (int)xRemain  % 60;
    int minute = ((int)xRemain / 60) % 60;
    int hours = ((int)xRemain / 3600) % 24;
    int day   = xRemain / 3600/24;
    
    NSMutableString *secondStr = [NSMutableString stringWithFormat:@"%02d",second];
    NSMutableString *minuteStr = [NSMutableString stringWithFormat:@"%02d",minute];
    NSMutableString *hoursStr = [NSMutableString stringWithFormat:@"%02d",hours];
    NSMutableString *dayStr   = [NSMutableString stringWithFormat:@"%02d",day];
    
    
    NSString *result = [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@",dayStr,dayUnit,hoursStr,hourUnit,minuteStr,minUnit,secondStr,secUnit];
    
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",result]];
    if (isChangeUnitColor) {
        NSRange range_d = [result rangeOfString:dayUnit];
        NSRange range_h = [result rangeOfString:hourUnit];
        NSRange range_m = [result rangeOfString:minUnit];
        NSRange range_s = [result rangeOfString:secUnit];
        
        [attributeString setAttributes:@{NSForegroundColorAttributeName:dayUnitColor} range:range_d];
        [attributeString setAttributes:@{NSForegroundColorAttributeName:hourUnitColor} range:range_h];
        [attributeString setAttributes:@{NSForegroundColorAttributeName:minUnitColor} range:range_m];
        [attributeString setAttributes:@{NSForegroundColorAttributeName:secUnitColor} range:range_s];
    }
    
    xLimitLabel.attributedText = attributeString;
}

@end
